package com.jinsi.service.tang.iml;

import com.jinsi.mapper.tang.ProductMapper;
import com.jinsi.pojo.Commodity;
import com.jinsi.pojo.ProductZtree;
import com.jinsi.service.tang.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 商品列表
 * @author 唐文博
 * @Date 2022-08-05
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class ProductServiceImpl implements ProductService {
    @Autowired
    private ProductMapper productMapper;

    /**
     * 修改树节点名称
     * @param classifyTitle
     * @param classifyId
     */
    @Override
    public void updateTreeName(String classifyTitle, int classifyId) {
        productMapper.updateProduct(classifyTitle,classifyId);
    }

    /**
     * 删除树节点名称
     * @param classifyId
     * @throws Exception
     */
    @Override
    public void delTreeNode(int classifyId) throws Exception {
        int i = productMapper.delProduct(classifyId);
        if (i == 0) {
            throw new RuntimeException();
        }
    }

    /**
     * 添加树节点名称
     * @param productZtree
     * @throws Exception
     */
    @Override
    public void addTreeNode(ProductZtree productZtree) throws Exception {
        int i = productMapper.insertProduct(productZtree);
        if (i == 0) {
            throw new Exception();
        }
    }

    /**
     * 筛选搜索查询,根据商品名称、商品分类、商品状态、商品标签查询
     * @param commodityName 根据商品的名称进行搜索查询
     * @param classifyTitle 根据商品的名分类进行搜索查询
     * @param commodityState 根据商品的状态进行搜索查询
     * @param commodityIsdel 获取假删除状态
     * @param classifyId 商品分类的id
     * @return
     */
    @Override
    public List<Commodity> getCommoditySee(String commodityName, String classifyTitle,
                                          Integer commodityState, Integer commodityIsdel,
                                          Integer classifyId) {
        return productMapper.getCommoditySee(commodityName,classifyTitle,
                commodityState,commodityIsdel,classifyId);
    }

    /**
     * 点击上架 修改上架状态
     * @param commodityId
     * @param commodityState
     * @return
     */
    @Override
    public int updateCommodity(Integer commodityId, Integer commodityState) {
        return productMapper.updateCommodity(commodityId,commodityState);
    }
}
